package com.ttg.web.controller.common;


import com.ttg.common.entities.BaseResult;
import com.ttg.common.utils.RequestParamsManager;
import com.ttg.model.dto.ManageIndexReqDTO;
import com.ttg.web.service.ManageRoleIndexService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("登录管理模块")
@RestController
@RequestMapping("/manage")
public class ManageIndexController {
    @Autowired
    private ManageRoleIndexService manageIndexService;
    @ApiOperation("登录验证")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",required = true,value = "管理员名称",paramType = "form"),
            @ApiImplicitParam(name = "password",required = true,value = "密码",paramType = "form"),
            @ApiImplicitParam(name = "xWidth",required = true,value = "图片验证码",paramType = "form")
    })
    @RequestMapping("/checkLogin")
    public BaseResult checkLogin(@RequestBody(required = false) String data){
        ManageIndexReqDTO reqDto = RequestParamsManager.transformRequestParam(data, ManageIndexReqDTO.class);
        return BaseResult.success(manageIndexService.checkLogin(reqDto));
    }
    @ApiOperation("获取验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",required = true,value = "管理员名称",paramType = "form")
    })
    @RequestMapping("/loginCode")
    public BaseResult loginCode(@RequestBody(required = false) String data){
        ManageIndexReqDTO reqDto = RequestParamsManager.transformRequestParam(data, ManageIndexReqDTO.class);
        return BaseResult.success(manageIndexService.loginCode(reqDto));
    }
    @ApiOperation("退出登录")
    @RequestMapping("/logout")
    public BaseResult logout(){
        return BaseResult.success(manageIndexService.logout());
    }

}
